/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package framework.agendaFactory;

import framework.agendaFactory.lib.InternalFrame;
import framework.agendaFactory.lib.ToolBar;
import java.awt.Container;
import javax.swing.GroupLayout;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

/**
 *
 * @author Sergio Carlos Peres
 */
public abstract class BasicAgendaFactory extends AgendaFactory{
    
    @Override
    public InternalFrame criaInternalFrame(String title, AgendaFactory factory) {
        InternalFrame frame = new InternalFrame(title) {

            @Override
            public void preencherTabela(String sql) {
                preencheTabela(sql);
            }

            @Override
            public void preencherComboBox(String sql) {
                preencheComboBox(sql);
            }

            @Override
            public void ativarCamposAdicionar(boolean b) {
                ativaCamposAdicionar(b);
            }

            @Override
            public void limparAdicionar() {
                limpaAdicionar();
            }

            @Override
            public Object getTelaAdd() {
                return getTela();
            }

            @Override
            public JTable getTabela() {
                return getTabelaLista();
            }

            @Override
            public void setTelaAdd(Object o) {
                setTela(o);
            }

            @Override
            public void rePaintGroups() {
                rePaintGroupsA();
            }

            @Override
            public Integer getGroupSelected() {
                return getGroupSelectedA();
            }
            
        };
        
        frame.setClosable(true);
        frame.setIconifiable(true);
        frame.setMaximizable(true);
        frame.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrameOpened(evt);
            }
        });
        frame.setFactory(factory);
        
        return frame;
    }
    
    @Override
    public ToolBar criaToolBar(java.awt.event.ActionListener listener) {
        ToolBar toolBar = new ToolBar(listener);
        return toolBar;
    }

    @Override
    public GroupLayout criaLayout(Container container, ToolBar toolBar) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(container);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addContainerGap())
        );
        
        return layout;
    }
    
    @Override
    public GroupLayout criaLayout(Container container, ToolBar toolBar, JTabbedPane tabbedPane) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(container);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tabbedPane)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        
        return layout;
    }

    @Override
    public JTabbedPane criaTabbebPane(JPanel[] panel, String[] titulos) {
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.setAutoscrolls(true);
        tabbedPane.setFont(new java.awt.Font("Tahoma", 1, 12));
        
        for (int i = 0; i < panel.length; i++) 
            tabbedPane.addTab(titulos[i], panel[i]);
        
        return tabbedPane;
    }
    
    public void jInternalFrameClosed(javax.swing.event.InternalFrameEvent evt){
        this.controle = false;
    }
    
    @Override
    public void setParametroConexao() {
        framework.dal.Link.setParameters("localhost/agenda", "agenda", "root", "ufu2013", "item");
    }
    
    public abstract void jInternalFrameOpened(javax.swing.event.InternalFrameEvent evt);
    
    public abstract void preencheTabela(String sql);
    public void preencheComboBox(String sql) {}
    public abstract void ativaCamposAdicionar(boolean b);
    public abstract void limpaAdicionar();
    public abstract Object getTela();
    public abstract void setTela(Object o);
    public void rePaintGroupsA() {}
    public Integer getGroupSelectedA() { return null; }
    
}